package com.ryan.demo.jms.listener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.log4j.Logger;

import com.ryan.demo.jms.consumer.ConsumerService;

public class ReceiveMessageListener implements MessageListener {

	private ConsumerService springConsumerService;

	private String correlationId;
	
	private static final Logger logger = Logger
			.getLogger(ReceiveMessageListener.class);

	public void onMessage(Message message) {
		if (message instanceof TextMessage) {
			TextMessage text = (TextMessage) message;
			try {
				logger.info("Received message:" + text.getText());
				springConsumerService.receiveMessageByCorrelationId(correlationId);
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
	}

	public void setSpringConsumerService(ConsumerService springConsumerService) {
		this.springConsumerService = springConsumerService;
	}

	public void setCorrelationId(String correlationId) {
		this.correlationId = correlationId;
	}

}
